package com.gogowan.agroenterprise.newview;

import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.gogowan.agroenterprise.MyApplication;
import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.base.BaseActivity;
import com.gogowan.agroenterprise.contorl.RetrofitUtil.GsonUtil;
import com.gogowan.agroenterprise.model.DH_Result;
import com.gogowan.agroenterprise.model.DH_Sub_Request;
import com.gogowan.agroenterprise.model.LoginResultInfo;
import com.gogowan.agroenterprise.model.ResultInfo;
import com.gogowan.agroenterprise.model.UserType;
import com.gogowan.agroenterprise.utils.Util;
import com.gogowan.agroenterprise.utils.Utils;

public class DH_InforMation_Activity extends BaseActivity {
    private DH_Result.ExchangeListInfoBean bean;
    private TextView information_tv, subTv;
    
    private ProgressDialog progressDialog;
    private String OutStorageNO;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_activity);
        OutStorageNO=getIntent().getStringExtra("OutStorageNO")+"";
        SharedPreferences preferences = getSharedPreferences("LoginINfo", MODE_PRIVATE);
        
        
        bean=(DH_Result.ExchangeListInfoBean)getIntent().getSerializableExtra("bean");
        information_tv=(TextView)findViewById(R.id.text_tv);
        String val= "出库单号:"+bean.getOutStorageNo()+
                "\n产品名称:"+bean.getMaterialName()+
                "\n入库数量:"+bean.getMaCount()+
                "\n入库垛数:"+bean.getDuoCount()+
                "\n入库箱数:"+bean.getBoxCount();
        information_tv.setText(val);
        subTv=(TextView)findViewById(R.id.in_storage_qrrk_btn);
        subTv.setText("确认调换");
        findViewById(R.id.goods_allocation_add_fh_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(207);
                finish();
            }
        });
        if (MyApplication.mSettings.getInt("usertype",0)== UserType._JING_XIAO_SHANG.getTypeID()||bean.getIsExchange().equals("1")){
            subTv.setVisibility(View.GONE);
        }
        subTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SubHttp();
            }
        });
    }

    private void SubHttp() {
        DH_Sub_Request request=new DH_Sub_Request();
        request.setDealerId(bean.getDealerId());
        request.setDetailId(bean.getExID());
        if (Utils.isEmpty(OutStorageNO)){
            request.setOutStorageNo(bean.getOutStorageNo());
        }else {
            request.setOutStorageNo(OutStorageNO);

        }
        request.setQrCode(bean.getQrcode());
        Http(request, "", progressDialog, new RetrofitHttpListener() {
            @Override
            public void OnJson(String str) {
                if (!Utils.isEmpty(str)){
                    ResultInfo resultInfo= GsonUtil.GsonToBean(str,ResultInfo.class);
                    if (resultInfo!=null){
                        if (resultInfo.getResult()>0){
                            showToast(resultInfo.getResultinfo());
                            setResult(206);
                            finish();
                        }
                    }
                }
            }
        });
    }
}
